#!/usr/bin/env perl

use utf8;
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use String::ShellQuote qw( shell_quote );
use DBDefs;
use MusicBrainz::Server::DatabaseConnectionFactory;

if ($ARGV[0])
{
    my %db = %{ $MusicBrainz::Server::DatabaseConnectionFactory::databases{uc($ARGV[0])} };

    my $port = $db{port} // '5432';
    my $host = $db{host} // 'localhost';

    print 'export PGHOST=' . shell_quote($host) . "\n";
    print 'export PGPORT=' . shell_quote($port) . "\n";
    print 'export PGDATABASE=' . shell_quote($db{database}) . "\n";
    print 'export PGUSER=' . shell_quote($db{username}) . "\n";
    print 'export PGPASSWORD=' . shell_quote($db{password}) . "\n" if $db{password};
}
else
{
    print "Usage: database_configuration <DBNAME>\n";
    print "\n";
    print "\tDBNAME\tThe database name (READWRITE or TEST)\n";
    print "\n";
    exit 2;
}
